﻿using Hazza.UserInput.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;


namespace Hazza.UserInput.Drivers
{
    public class TextInputPartDriver : ContentPartDriver<TextInputPart>
    {
        protected override string Prefix
        {
            get { return "TextInputPart"; }
        }

        protected override DriverResult Display(TextInputPart part, string displayType, dynamic shapeHelper)
        {
            return ContentShape("Parts_TextInputPart",
                () => {
                    return shapeHelper.Parts_TextInputPart(
                        Model: part);
                });
        }

        protected override DriverResult Editor(TextInputPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_TextInputPart_Edit",
                () => shapeHelper.EditorTemplate(
                    TemplateName: "Parts/TextInputPart",
                    Model: part,
                    Prefix: Prefix));
        }

        protected override DriverResult Editor(TextInputPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}